package com.onion.codegen;

import java.util.HashSet;
import java.util.Set;

import com.onion.codegen.bean.GeneratorProperties;
import com.onion.codegen.db.DbProperties;
import com.onion.codegen.gen.BaseGenerator;
import com.onion.codegen.gen.ControllerGenerator;
import com.onion.codegen.gen.EntityGenerator;
import com.onion.codegen.gen.MapperGenerator;
import com.onion.codegen.gen.MapperXmlGenerator;
import com.onion.codegen.gen.ServiceGenerator;
import com.onion.codegen.gen.ServiceImplGenerator;

public class CodeGen {
	public static void main(String[] args) throws Exception {

		//数据库驱动及连接
		DbProperties dbProperties = new DbProperties();
		dbProperties.setDriver("com.mysql.cj.jdbc.Driver");
		dbProperties.setUrl("jdbc:mysql://你自己的MYSQL地址:3306/hotel?characterEncoding=utf8&serverTimezone=GMT%2B8");
		dbProperties.setUserName("root");
		dbProperties.setPassWord("root");
		
		//指定要生成代码的数据表
		GeneratorProperties javaEntityProperties =new GeneratorProperties();
		Set<String> genTables = new HashSet<String>();
		genTables.add("abnormal_order");
		genTables.add("abnormal_account");
		
		/***********************生成Entity***************************/
		javaEntityProperties.setDbProperties(dbProperties);
		javaEntityProperties.setGenTables(genTables);
		javaEntityProperties.setAuthor("yangsong");
		javaEntityProperties.setBaseFoler("D:/gitcode/dossen-nszs-api/src/main/java");
		//packageDbProperties.setBaseFoler("D:/gitcode/codegen/src/main/java");
		javaEntityProperties.setPackageName("net.fongtech.test.entity");
//		javaEntityProperties.setSuperClass("com.test.BaseEntity.java");
		javaEntityProperties.setForce(true);	//强制重写
		
		//生成Entity
		BaseGenerator baseGenerator = new EntityGenerator();
		baseGenerator.setJavaEntityProperties(javaEntityProperties);
		baseGenerator.initAndGenClass();
		
		
		
		/***********************生成Mapper***************************/
		javaEntityProperties.setDbProperties(dbProperties);
		javaEntityProperties.setGenTables(genTables);
//		javaEntityProperties.setBaseFoler("src/main/java");
		javaEntityProperties.setBaseFoler("D:/gitcode/dossen-nszs-api/src/main/java");
		//packageDbProperties.setBaseFoler("D:/gitcode/codegen/src/main/java");
		javaEntityProperties.setPackageName("net.fongtech.test.mapper");
//		javaEntityProperties.setSuperClass("com.test.BaseEntity.java");
		javaEntityProperties.setForce(true);	//强制重写
		BaseGenerator mapperGenerator = new MapperGenerator();
		mapperGenerator.setJavaEntityProperties(javaEntityProperties);
		mapperGenerator.initAndGenClass();
		
		
		/***********************生成Service***************************/
		javaEntityProperties.setDbProperties(dbProperties);
		javaEntityProperties.setGenTables(genTables);
//		javaEntityProperties.setBaseFoler("src/main/java");
		javaEntityProperties.setBaseFoler("D:/gitcode/dossen-nszs-api/src/main/java");
		//packageDbProperties.setBaseFoler("D:/gitcode/codegen/src/main/java");
		javaEntityProperties.setPackageName("net.fongtech.test.service");
//		javaEntityProperties.setSuperClass("com.test.BaseEntity.java");
		javaEntityProperties.setForce(true);	//强制重写
		BaseGenerator serviceGenerator = new ServiceGenerator();
		serviceGenerator.setJavaEntityProperties(javaEntityProperties);
		serviceGenerator.initAndGenClass();
		
		
		
		/***********************生成ServiceImpl***************************/
		javaEntityProperties.setDbProperties(dbProperties);
		javaEntityProperties.setGenTables(genTables);
//		javaEntityProperties.setBaseFoler("src/main/java");
		javaEntityProperties.setBaseFoler("D:/gitcode/dossen-nszs-api/src/main/java");
		//packageDbProperties.setBaseFoler("D:/gitcode/codegen/src/main/java");
		javaEntityProperties.setPackageName("net.fongtech.test.service.impl");
//		javaEntityProperties.setSuperClass("com.test.BaseEntity.java");
		javaEntityProperties.setForce(true);	//强制重写
		BaseGenerator serviceImplGenerator = new ServiceImplGenerator();
		serviceImplGenerator.setJavaEntityProperties(javaEntityProperties);
		serviceImplGenerator.initAndGenClass();
		
		/***********************生成Controller***************************/
		javaEntityProperties.setDbProperties(dbProperties);
		javaEntityProperties.setGenTables(genTables);
//		javaEntityProperties.setBaseFoler("src/main/java");
		javaEntityProperties.setBaseFoler("D:/gitcode/dossen-nszs-api/src/main/java");
		//packageDbProperties.setBaseFoler("D:/gitcode/codegen/src/main/java");
		javaEntityProperties.setPackageName("net.fongtech.test.controller");
//		javaEntityProperties.setSuperClass("com.test.BaseEntity.java");
		javaEntityProperties.setForce(true);	//强制重写
		BaseGenerator controllerGenerator = new ControllerGenerator();
		controllerGenerator.setJavaEntityProperties(javaEntityProperties);
		controllerGenerator.initAndGenClass();
		
		
		/***********************生成Mapper.xml***************************/
		javaEntityProperties.setDbProperties(dbProperties);
		javaEntityProperties.setGenTables(genTables);
//		javaEntityProperties.setBaseFoler("src/main/java");
		javaEntityProperties.setBaseFoler("D:/gitcode/dossen-nszs-api/src/main/java");
		//packageDbProperties.setBaseFoler("D:/gitcode/codegen/src/main/java");
		javaEntityProperties.setPackageName("net.fongtech.hotel.point.resource");
//		javaEntityProperties.setSuperClass("com.test.BaseEntity.java");
		javaEntityProperties.setForce(true);	//强制重写
		BaseGenerator mapperXmlGenerator = new MapperXmlGenerator();
		mapperXmlGenerator.setJavaEntityProperties(javaEntityProperties);
		mapperXmlGenerator.initAndGenClass();
	}
}
